{extend name="base"/}
{blcok name="title"}用户管理{/block}
{block name="main"}
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>用户管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:500px">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:400px">
                    <input type="text" name="login_name" placeholder="搜索内容" id="login_name" value="{$login_name}" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn" onclick="search()" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>
    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
    <button class="layui-btn" onclick="user_management_add('添加用户','{:url('admin/Users/userAdd')}','600','500')"><i
            class="layui-icon">&#xe608;</i>添加
    </button>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <input type="checkbox" id="checkAll" name="" value="">
            </th>
            <th>ID</th>
            <th>用户名</th>
            <th>密码</th>
            <th>用户角色</th>
            <th>性别</th>
            <th>最近登录时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        {volist name="users" id="vo"}
        <tbody>
        <tr>
            <td><input type="checkbox" value="{$vo.staff_id}" id="ids"  class="idsss"   name="checkbox[]"></td>
            <td>{$vo.staff_id}</td>
            <td><a style="cursor:pointer" href="{:url('admin/users/userDetail',array('id'=>$vo['staff_id']))}">{$vo.login_name}</a>
            </td>
            <td>{$vo.login_pass}</td>
            <td>{$vo.login_name}</td>
            <td>{if condition='$vo.sex eq 0'}男{else/}女{/if}</td>
            <td>{$vo['last_time']|date="Y-m-d H:i:s",###} </td>
            <td class="td-status">
                {if condition="$vo['staff_status'] eq 1"}
                <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                {else /}
                <span class="layui-btn layui-btn-normal layui-btn-mini">已停用</span>
                {/if}
            </td>
            <td>
                <!--0停用-->
                {if condition="$vo['staff_status'] eq 1"}
                <a style="text-decoration:none" onclick="member_stop(this,'{$vo.staff_id}',0)" title="停用" ><i class="layui-icon">&#xe61a;</i></a>
                {else /}
                <a style="text-decoration:none" onclick="member_start(this,'{$vo.staff_id}',1)" title="启用" ><i class="layui-icon">&#xe619;</i></a>
                {/if}
                <a title="编辑" href="{:url('admin/Users/userEdit',array('id'=>$vo['staff_id']))}" class="ml-5" style="text-decoration:none"><i class="layui-icon">&#xe642;</i></a>
                <a style="text-decoration:none" href="{:url('admin/users/usersEditPwd',array('id'=>$vo['staff_id']))}" title="修改密码"><i class="layui-icon">&#xe631;</i></a>
                <a title="删除" href="javascript:;" onclick="member_del(this,'{$vo.staff_id}')" style="text-decoration:none"><i class="layui-icon">&#xe640;</i></a>
            </td>
        </tr>
        </tbody>
        {/volist}
    </table>


</div>
<br/><br/><br/>
{/block}
<script src="__ROOT__/static/admin/role/lib/layui/layui.js" charset="utf-8"></script>
<script src="__ROOT__/static/admin/role/js/x-layui.js" charset="utf-8"></script>
{block name="script"}
<script>
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入

        laypage({
            cont: 'page'
            ,pages: 100
            ,first: 1
            ,last: 100
            ,prev: '<em><</em>'
            ,next: '<em>></em>'
        });

        var start = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

    });

    $("#checkAll").bind("click",function(){
        $("input[name='checkbox[]']").prop("checked",this.checked);
         });

    //批量删除提交
    function delAll(){
     layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
         var obj = $('input[type="checkbox"]:checked');
         var html = [];
         $(obj).each(function(){
             html.push($(this).val());
         });
         var arr=html;
         //去除空值
         var trim = function(s) { return s.replace(/\s+/g,'');}
         var re = [];
         for(var i = 0, len = arr.length; i < len; i++) {
             if(trim(arr[i]).length > 0) re[re.length] = arr[i];
         }
         var re2 = re.join(',');
         var params = {};
         params.ids = re2;
        $.post("{:url('admin/Users/del')}",params,function(data){
           if(data[0]==1){
               layer.msg('删除成功', {time:2000,icon: 1});
               location.href="{:url('admin/Users/user')}";
           }else{
               layer.msg('删除失败',{time:1000,icon:1});
           }
        });
        });
    }
    //搜索
    function search(){
        var params= {};
        params.login_name = $.trim($('#login_name').val());
        $.post("{:url('admin/Users/user')}",params,function(data){
            //代码暂时没有了
        });

    }
    /*用户-添加*/
    function user_management_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }

    /*用户-停用*/
    function member_stop(obj,id,s){
            var params ={};
            params.s = s;
            params.id =id;
            if(params.id==1){
                layer.msg('您是超级管理员、无法停用自己');
                return false;
            }else{
                layer.confirm('确定要停吗?',function(){
                    $.post("{:url('admin/Users/setStatus')}",params,function(data){
                       if(data>0){
                           layer.msg('已停用', {icon: 1,time:1000});
                           setTimeout('location.replace(location.href)',1500);
                       }
                    });

                });

            }
    }

    /*用户-停用*/
    function member_start(obj,id,s){
        var params ={};
        params.s = s;
        params.id =id;
        if(params.id==1){
            layer.msg('您是超级管理员、无法操作自己');
            return false;
        }else{
            layer.confirm('确定启用吗?',function(){
                $.post("{:url('admin/Users/setStatus')}",params,function(data){
                    if(data>0){
                        layer.msg('已启用', {icon: 1,time:1000});
                        setTimeout('location.replace(location.href)',1500);
                    }
                });

            });

        }
    }

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            var params = {};
             params.staff_id = id;
            $.post("{:url('admin/Users/usersDel')}",params,function(data){
                if(data>0){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                }
            });

        });
    }
</script>
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
{/block}